package edu.guet.server.service;

import edu.guet.server.mapper.ExcellentCourseMapper;
import edu.guet.server.model.dto.ExcellentCourseDTO;
import edu.guet.server.model.vo.ExcellentCourseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExcellentCourseService {
    @Autowired
    private ExcellentCourseMapper excellentCourseMapper;

    /**
     * 按照id查精品课程信息
     *
     * @param excellentCourseDTO
     * @return
     */
    public List<ExcellentCourseVO> showCourses(ExcellentCourseDTO excellentCourseDTO) {
        Integer course_id = excellentCourseDTO.getCourse_id();
        return excellentCourseMapper.findCourseInfo(course_id);
    }

    /**
     * 默认查询方法，按时间降序
     *
     * @return
     */
    public List<ExcellentCourseVO> findCourseOrderByTime() {
        return excellentCourseMapper.findCourseOrderByTime(1);
    }

    /**
     * 检查id是否存在
     *
     * @param courseDTO
     * @return存在返回true，否则返回false
     */
    public boolean checkIdsExist(ExcellentCourseDTO courseDTO) {
        List<Integer> semester_id = courseDTO.getSemesterIds();
        for (Integer id : semester_id) {
            if (excellentCourseMapper.checkId(id) == null) {
                return false;
            }
        }
        return true;
    }
}
